//
//  SortCell.m
//  shiweiquanjing
//
//  Created by xftt on 14-7-9.
//
//

#import "SortCell.h"
//#import <QuartzCore/QuartzCore.h>

@implementation SortCell
{
    UIImageView *selectIcon;
    UILabel *lbName;
    UITextField *txtName;
}

- (id)initWithType:(BOOL)isEdit reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        if (isEdit) {
            [self InitEdit];
        }
        else
        {
            [self Initshow];
        }
    }
    return self;
}

-(void)Initshow
{
    [self setBackgroundColor:[UIColor clearColor]];
    UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(40, 10, 65, 50)];
    [imgv setImage:[UIImage imageNamed:@"finder"]];
    [self addSubview:imgv];
    lbName = [[UILabel alloc] initWithFrame:CGRectMake(125, 10, 630, 50)];
    [lbName setBackgroundColor:[UIColor clearColor]];
    [lbName setTextColor:[UIColor colorWithHexString:@"#AAAAAA"]];
    [lbName setFont:[UIFont systemFontOfSize:20]];
    [self addSubview:lbName];
    UIImageView *igv = [[UIImageView alloc] initWithFrame:CGRectMake(780, 23, 18, 32)];
    [igv setImage:[UIImage imageNamed:@"Goto"]];
    [self addSubview:igv];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(40, 69, 804, 1)];
    [line setBackgroundColor:[UIColor colorWithHexString:@"#666666"]];
    [self addSubview:line];
}

-(void)InitEdit
{
    [self setBackgroundColor:[UIColor clearColor]];
    selectIcon = [[UIImageView alloc] initWithFrame:CGRectMake(40, 25, 30, 30)];
    [selectIcon setImage:[UIImage imageNamed:@"slt"]];
    [self addSubview:selectIcon];
    UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(100, 10, 65, 50)];
    [imgv setImage:[UIImage imageNamed:@"finder"]];
    [self addSubview:imgv];
    txtName = [[UITextField alloc] initWithFrame:CGRectMake(185, 10, 500, 50)];
    txtName.layer.borderColor = [[UIColor colorWithHexString:@"#515151"] CGColor];
    txtName.layer.borderWidth = 1;
    [txtName setDelegate:self];
    [txtName setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
    [txtName setBackgroundColor:[UIColor clearColor]];
    [txtName setTextColor:[UIColor colorWithHexString:@"#AAAAAA"]];
    [txtName setFont:[UIFont systemFontOfSize:20]];
    [self addSubview:txtName];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(100, 69, 744, 1)];
    [line setBackgroundColor:[UIColor colorWithHexString:@"#666666"]];
    [self addSubview:line];
}

-(void) setIsSelect:(BOOL)select
{
    _isSelect = select;
    if (_isSelect) {
        [selectIcon setImage:[UIImage imageNamed:@"sltd"]];
    }else{
        [selectIcon setImage:[UIImage imageNamed:@"slt"]];
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if ([txtName.text length]>0) {
        [self.FController saveSort:txtName.text path:_row];
    }
}

-(void)setSort:(NSDictionary *)sort
{
    _sort = sort;
    [lbName setText:[sort objectForKey:@"sortname"]];
    [txtName setText:[sort objectForKey:@"sortname"]];
}

@end
